var webPath = "";
var editor;
$(document).ready(function(){
	webPath = $("#webPath").val();
	var msg = $("#message").val();
	if(msg != ""){
		alert(msg);
	}
});

function validateMsg(){
	var msgTitle = $("#msgTitle").val();
	var msgSource = $("#msgSource").val();
	var msgContent = $("#msgContent").val();
	if(string.trim(msgTitle) == ""){
		alert("请输入信息标题！");
		$("#msgTitle").focus();
		return false;
	}
	if(string.trim(msgSource) == ""){
		alert("请输入信息来源！");
		$("#msgSource").focus();
		return false;
	}
	if(string.trim(msgContent) == ""){
		alert("请输入信息内容！");
		return false;
	}
	return true;
}

function saveMsg(){
	$("#msgState").val("0");
	$("#msgContent").val(KE.util.getData("editor"));
	if(validateMsg()){
		var method = $("#method").val();
		if(method == ""){
			method = "create";
		}
		document.form1.action = webPath + "/admin/message!"+method+".action";
		document.form1.submit();
	}
}

function submitMsg(){
	$("#msgState").val("1");
	$("#msgContent").val(KE.util.getData("editor"));
	if(validateMsg()){
		var method = $("#method").val();
		if(method == ""){
			method = "create";
		}
		document.form1.action = webPath + "/admin/message!"+method+".action";
		document.form1.submit();
	}
}

function changeType(val){
	var data = {"parentId": val};
	$.ajax({
		type: "POST",
		cache: false,
		dataType: "json",
		url: webPath+"/admin/message!changeType.action",
		data: data,
		success: function(json){
			if(json != null && json.typeSubList != null && json.typeSubList.length > 0){
				var strHtml = '';
				$.each(json.typeSubList,function(i,value){
					strHtml += showSubType(value);
				});
				$("#id_subType").html(strHtml);
			}else{
				alert("信息栏目查询失败！");
			}
		}
	});
}

function showSubType(value){
	var menuId = value.menuId;
	var menuName = value.menuName;
	var strHtml = '<option value="'+menuId+'">'+menuName+'</option>';
	return strHtml;
}

function changeListType(val){
	if(val==''){
		
		$("#id_subType").html('<option value="">--请选择--</option>');
		return;
	}
	var data = {"parentId": val};
	$.ajax({
		type: "POST",
		cache: false,
		dataType: "json",
		url: webPath+"/admin/message!changeType.action",
		data: data,
		success: function(json){
			if(json != null && json.typeSubList != null && json.typeSubList.length > 0){
				var strHtml = '<option value="">--请选择--</option>';
				$.each(json.typeSubList,function(i,value){
					strHtml += showListSubType(value);
				});
				$("#id_subType").html(strHtml);
			}else{
				alert("信息栏目查询失败！");
			}
		}
	});
}

function showListSubType(value){
	var menuId = value.menuId;
	var menuName = value.menuName;
	var strHtml = '<option value="'+menuId+'">'+menuName+'</option>';
	return strHtml;
}